//
//  User.swift
//  DSWeibo
//
//  Created by J on 16/4/24.
//  Copyright © 2016年 J. All rights reserved.
//

import UIKit

class User: NSObject {

    /// id
    var id: Int = 0
    /// 昵称
    var name: String?
    /// 用户头像
    var profile_image_url: String?{
        
        didSet{
            if let url = profile_image_url{
                profile_image_url_URL = NSURL(string: url)
            }
        }
    }
    
    /// 认证类型
    var verified: Bool = false
    /// 用户的认证类型: -1: 没有认证 0认证用户 2,3,5企业用户 220:达人
    var verified_type: Int = -1{
        didSet{//赋值之后设置认证图标
            switch verified_type {
            case 0 :
                vetifiedImage = UIImage(named:"avatar_vip")

            case 2, 3, 5 :
                vetifiedImage = UIImage(named:"avatar_enterprise_vip")
                
            case 220 :
                vetifiedImage = UIImage(named:"avatar_grassroot")

            default:
                vetifiedImage = nil
            }
        }
    }
    /// 用于保存用户头像URL
    var profile_image_url_URL: NSURL?
    /// 保存当前用户的认证图片
    var vetifiedImage: UIImage?

        /// 会员等级
    var mbrankImage: UIImage?
    var mbrank: NSInteger  = 0{//基本数据类型要初始化不然没值
        didSet{
            if mbrank > 0 && mbrank < 7{
                mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            }
        }
    }
    
    
    //字典转模型
    
    init(dic:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dic)
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        print( "\(key):\(value)")
    }
    
    
    var properties = ["id","name","profile_image_url","verified","verified_type"]
    
    override var description: String{
        let dict = dictionaryWithValuesForKeys(properties)
        return"\(dict)"
        
    }

    
}
